import homework_module


def homework_1():
    """
    有7个整数，其中三个数出现两次，1个数出现一次，找出那个出现一次的数
    :return:
    """
    num = [ 2, 2, 3, 3, 9, 4, 4, 8, 8]
    # i = 0
    # while i < len(num):
    #     if num.count(num[i]) == 1:
    #         print(num[i])
    #     i += 1

    # 优化
    result = 0
    for i in num:
        result ^=i  # 异或两个的就是0
    print(result)

def homework_2():
    """
    for循环，从1打印到20，横着打为一排
    :return:
    """
    for i in range(21):
        print(i,end='  ')


def homework_3_say_hello(x):
    """
    打印x次hello
    :return:
    """
    for i in range(x):
        print('hello')


def homework_4():
    """
    引用homework_module的函数
    :return:
    """
    homework_module.print_line()


def homework_7_difficult():
    """
    有8个整数，其中3个出现了2次，2个出现了1次，找出出现了一次的那两个数
    :return:
    """
    num = [2, 2, 3, 3, 4, 4, 8, 9]
    # i = 0
    # while i < len(num):
    #     if num.count(num[i]) == 1:
    #         print(num[i])
    #     i += 1
    # 把8:0000 1000和9:0000 1001分到两堆，对每一堆单独异或
    result = 0
    for i in num:
        result ^= i  # 异或两个的就是0
    print(result)
    # 结果是1：0000 0001   说明这两个数的0001位不同，以1异或即可分开
    # 使用result对原有列表遍历一遍就分为两部分
    list1 = []
    list2 = []
    for i in num:
        if result & i :
            list1.append(i)
        else:
            list2.append(i)
    print(list1,list2) # 此时已经分开了
    result2,result3 = 0,0
    for i in list1:
        result2 ^= i  # 异或两个的就是0
    for i in list2:
        result3 ^= i  # 异或两个的就是0
    print(result2,result3)



if __name__ == '__main__':
    # homework_1()
    # homework_2()
    # homework_3_say_hello(3)
    # homework_4()
    homework_7_difficult()